package com.bt.lms.ui.page.classes;

import com.bt.lms.ui.action.divide.plan.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;

/**
 * 手动分班页面
 */
public class ManualShift extends VBox {

    /**
     * 大盒子
     */
    VBox vBox1 = new VBox();

    /**
     * 宽
     */
    private Integer preWidth = 1280;

    /**
     * 高
     */
    private Integer preHeight = 600;


    public ManualShift() {
        vBox1.setPrefSize(preWidth, preHeight);
        vBox1.setSpacing(40);
        vBox1.setPadding(new Insets(20));
        Label topLab = new Label("共有350名学员");
        Font font = Font.font("仿宋", FontWeight.BLACK, FontPosture.REGULAR, 25);
        topLab.setFont(font);
        //分班方式盒子
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        Label chooseLab = new Label("请选择分班方式：");
        Button randomShiftBtn = new Button("随机平均分班");
        randomShiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        Color rgb = Color.rgb(49, 193, 231);
        BackgroundFill backgroundFill = new BackgroundFill(rgb, null, null);
        Background background = new Background(backgroundFill);
        randomShiftBtn.setBackground(background);
        //事件
        RandomShiftBtnAction randomShiftBtnAction = new RandomShiftBtnAction();
        randomShiftBtn.setOnAction(randomShiftBtnAction);

        Button manualShiftBtn = new Button("手动分班");
        manualShiftBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        manualShiftBtn.setBackground(background);
        hBox.getChildren().addAll(chooseLab, randomShiftBtn, manualShiftBtn);
        //填写分班数
        HBox hBox1 = new HBox();
        hBox1.setSpacing(10);
        Label writeLab = new Label("填写分班数");
        TextField writeTF = new TextField();
        writeTF.setId("writeTF");
        Button affirmBtn = new Button("确认");
        affirmBtn.setBackground(background);

        VBox vBox = new VBox(); //VBox
        vBox.setSpacing(40);
        //确认按钮加事件
        affirmBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                String classNum = writeTF.getText();
                try {
                    int num = Integer.parseInt(classNum);
                    for (int i = 0; i < num - 1; i++) {
                        vBox.getChildren().add(new HandCondition());
                    }
                } catch (NumberFormatException e) {

                }
            }
        });


        affirmBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        hBox1.getChildren().addAll(writeLab, writeTF, affirmBtn);
        //标签
        Label tipLab = new Label("已分成4个班，请设定班级名称，设定班级人数，并选择对应学员");

        HBox hBox2 = new HBox();
        hBox2.setSpacing(180);
        Label classIDLab = new Label("班ID");
        Label classNameLab = new Label("设定班级名称");
        Label stuNumberLab = new Label("已选学员人数");
        Label selectLab = new Label("选择学员操作");
        hBox2.getChildren().addAll(classIDLab, classNameLab, stuNumberLab, selectLab);

        HBox hBox3 = new HBox();
        hBox3.setId("hBox3"); //设置ID
        hBox3.setSpacing(20);
        TextField iDTF = new TextField();
        iDTF.setPromptText("ID001");
        iDTF.setId("iDTF");
        TextField nameTF = new TextField();
        nameTF.setPromptText("请输入名称");
        nameTF.setId("nameTF");
        TextField handStuNoTF = new TextField();
        handStuNoTF.setPromptText("50");
        handStuNoTF.setId("handStuNoTF");
        Button addStuBtn1 = new Button("增加学员");
        addStuBtn1.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        addStuBtn1.setBackground(background);
        //增加学员事件
        AddStuBtnAction addStuBtnAction1 = new AddStuBtnAction();
        addStuBtn1.setOnAction(addStuBtnAction1);

        Button deleteStuBtn1 = new Button("删除学员");
        deleteStuBtn1.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        deleteStuBtn1.setBackground(background);
        //删除学员事件
        DeleteStuBtnAction deleteStuBtnAction1 = new DeleteStuBtnAction();
        deleteStuBtn1.setOnAction(deleteStuBtnAction1);

        hBox3.getChildren().addAll(iDTF, nameTF, handStuNoTF, addStuBtn1, deleteStuBtn1);

        //按钮盒子
        HBox hBox5 = new HBox();
        hBox5.setSpacing(10);
        Button previewResultsBtn = new Button("预览分班结果");
        previewResultsBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        previewResultsBtn.setBackground(background);

        //预览分班结果事件
        PrePageManualShiftBtnAction pageManualShiftPreBtnAction = new PrePageManualShiftBtnAction(this);
        previewResultsBtn.setOnAction(pageManualShiftPreBtnAction);

        Button cancelBtn = new Button("取消");
        cancelBtn.setCursor(Cursor.HAND); //添加鼠标移入出现小手图案
        //取消事件
        BackBtnAction backBtnAction = new BackBtnAction();
        cancelBtn.setOnAction(backBtnAction);

        hBox5.getChildren().addAll(previewResultsBtn, cancelBtn);

        //滚动条
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); //不让设置横滚动条
        scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS);
        scrollPane.setContent(vBox1);
        this.getChildren().add(scrollPane);

        vBox1.getChildren().addAll(topLab, hBox, hBox1, tipLab, hBox2, hBox3, vBox, hBox5);
    }
}
